package com.longge;

import java.util.Random;

/**
 * @创建人 xinglongge
 * @创建时间 2021/11/22
 * @描述
 */
public class ShuffleArr {

    private int[] nums;
    private int[] origin;

    public ShuffleArr(int[] nums) {
        this.nums = nums;
        this.origin = new int[nums.length];
        System.arraycopy(nums, 0, origin, 0, nums.length);
    }

    public int[] reset() {
        System.arraycopy(origin, 0, nums, 0, nums.length);
        return nums;
    }

    public int[] shuffle() {
        Random random = new Random();
        for (int i = 0; i < nums.length; i++) {
            int j = i + random.nextInt(nums.length - i);
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;
        }


        return nums;
    }


}
